<?php
if (!defined('admin')) {
    exit();
}
if (power('alevel') != 3) {
    die('error');
}
$cid = intval($_GET['cid']);
if ($cid == '') {
    die();
}
$query = M()->query("SELECT * FROM " . tableex('channel') . " where cid='$cid'");
$link = M()->fetchOne($query);
if (!$link) {
    die('no channel');
}
$csetting = json_decode($link['csetting'], 1);
?>
<?php admin_page_start('栏目配置') ?>
<h3><a style="margin-left:10px" href="?do=sadmin" class="actionBtn">返回</a>
    <?php
    if ($link['ckind'] == 1 || $link['ckind'] == 2) {
        echo('<a style="margin-left:10px" href="?do=sadmin_sbasic&cid=' . $cid . '" class="actionBtn">栏目变量</a>');
    }
    if ($link['ckind'] == 2) {
        echo('<a style="margin-left:10px" href="?do=sadmin_aindex&cid=' . $cid . '" class="actionBtn">字段管理</a>');
    }
    ?>
    <a href="?do=sadmin_cedit&cid=<?php echo($cid); ?>" class="actionBtn">栏目配置</a>
    <?php echo($link['cname']); ?> <i>栏目配置</i></h3>
<form id="form1" class="nowidth100p_form" method="post" action="?do=sadmin_ceditpost">
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="">
        <?php newtoken(); ?>
        <input type="hidden" name="cid" value="<?php echo($link['cid']); ?>">
        <tr>
            <td width="100" align="right">上级栏目</td>
            <td align="left">
                <select name="fid">
                    <?php
                    channel_select($link['fid']);
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td width="100" align="right">栏目名</td>
            <td align="left">
                <input type="text" name="cname" value="<?php echo(htmlspecialchars($link['cname'])); ?>"
                       class="inputtext" size=40>
            </td>
        </tr>
        <tr>
            <td width="100" align="right">栏目域名</td>
            <td align="left">
                <input class="inputtext inputshowtips" type="text" size="40" name="channeldomain"
                       value="<?php if (isset($csetting['channel_domain'])) {
                           echo($csetting['channel_domain']);
                       } ?>">
                <i><br>如 123.com <br>多个域名请用 ；分割<br>不需要绑定则留空<br>绑定域名后只允许绑定的域名访问该栏目<br>如果希望不限制域名则多个域名时加入*<br>绑定域名仅影响该页面中设置的栏目页面地址</i>
            </td>
        </tr>
        <tr>
            <td width="100" align="right">栏目备注</td>
            <td align="left">
                <input type="text" size="80" name="cnote" value="<?php if (isset($csetting['cnote'])) {
                    echo($csetting['cnote']);
                } ?>" class="inputtext">
            </td>
        </tr>
        <tr>
            <td width="100" align="right">栏目类型</td>
            <td align="left">
                <label><input type="radio" onclick="showtable(1);" name="ckind"
                              value="1" <?php if ($link['ckind'] == 1) {
                        echo('checked');
                    } ?>>单页栏目 </label>
                <label><input type="radio" onclick="showtable(2);" name="ckind"
                              value="2" <?php if ($link['ckind'] == 2) {
                        echo('checked');
                    } ?>>文章栏目</label>
                <label><input type="radio" onclick="showtable(5);" name="ckind"
                              value="5" <?php if ($link['ckind'] == 5) {
                        echo('checked');
                    } ?>>过渡栏目</label>
                <label><input type="radio" onclick="showtable(3);" name="ckind"
                              value="3" <?php if ($link['ckind'] == 3) {
                        echo('checked');
                    } ?>>前台链接</label>
                <label><input type="radio" onclick="showtable(4);" name="ckind"
                              value="4" <?php if ($link['ckind'] == 4) {
                        echo('checked');
                    } ?>>后台链接</label>
            </td>
        </tr>
        <tr>
            <td width="100" align="right">后台显示设置</td>
            <td align="left">
                <label><input type="checkbox" name="ifshowadmin" id="ifshowadmin"
                              value="0" <?php if ($link['ifshowadmin'] == 1) {
                        echo('checked');
                    } ?>>后台显示该栏目</label>
                <label><input type="checkbox" name="ifshowleft" id="ifshowleft"
                              value="0" <?php if ($link['ifshowleft'] == 1) {
                        echo('checked');
                    } ?>>后台左侧显示</label>
                <script type="text/javascript">
                    $(function () {
                        $('#ifshowadmin').change(function () {
                            if ($('#ifshowadmin').prop('checked')) {
                                $('#ifshowleft').prop('checked', true);
                                $('#ifshowleft').prop('disabled', false);
                            } else {
                                $('#ifshowleft').prop('checked', false);
                                $('#ifshowleft').prop('disabled', true);
                            }
                        });
                    });
                </script>
            </td>
        </tr>

    </table>
    <!-- 单页 -->
    <div style="display:none" id="table1">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class=""
               style="border-top:0px;border-bottom:0px;">
            <tr>
                <td width="100" align="right">前台设置</td>
                <td align="left">
                    <label><input type="checkbox" class="disable_tips1"
                                  name="ifshow1"<?php if (isset($link['ifshow']) && $link['ifshow'] == 0) {
                            echo(' checked');
                        } ?>>禁用该栏目</label>
                    <label><input type="checkbox" class="disable_tips11"
                                  name="ifshownav1"<?php if (isset($link['ifshownav']) && $link['ifshownav'] == 1) {
                            echo(' checked');
                        } ?>>导航栏显示</label>
                    <label><input type="checkbox"
                                  name="newwindow1"<?php if (isset($link['newwindow']) && $link['newwindow'] == 1) {
                            echo(' checked');
                        } ?>>新窗口中打开</label>
                </td>
            </tr>
            <tr>
                <td width="100" align="right">
                    栏目页面
                </td>
                <td align="left">
                    <label>栏目地址: <input class="inputtext" type="text" size="35" name="channel_url1"
                                        value="<?php if (isset($csetting['channel_url'])) {
                                            echo($csetting['channel_url']);
                                        } ?>"></label>
                    <label>&nbsp;&nbsp;&nbsp;&nbsp;页面缓存时间: <input class="inputtext" type="text" size="5"
                                                                  name="channel_urlcache1"
                                                                  value="<?php if (isset($csetting['channel_urlcache'])) {
                                                                      echo($csetting['channel_urlcache']);
                                                                  } else {
                                                                      echo('0');
                                                                  } ?>"> <i>秒</i></label>
                    <label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" id="template1"
                                                          name="template1"
                                                          value="<?php if (isset($csetting['template'])) {
                                                              echo($csetting['template']);
                                                          } ?>"></label>
                </td>
            </tr>
        </table>
    </div>
    <!-- 文章 -->
    <div style="display:none" id="table2">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class=""
               style="border-top:0px;border-bottom:0px;">
            <tr>
                <td width="100" align="right">栏目数据库表</td>
                <td align="left">
                    <label><input class="inputtext inputshowtips" type="text" size="25" name="articletable"
                                  value="<?php if (isset($csetting['articletable'])) {
                                      echo($csetting['articletable']);
                                  } else {
                                      echo('');
                                  } ?>">
                        <i class="ishowtips">
                            <?php
                            if (isset($csetting['articletable']) && strlen($csetting['articletable']) > 0) {
                                echo('默认文章表的字段尽量保持一致,不同类型的栏目请使用不同的表');
                            } elseif (isset($csetting['articletable']) && $csetting['articletable'] == '') {
                                echo('请填写该栏目在数据库中的表名(只限英文或英文+数字组合)，不要带前缀');
                            } else {
                                echo('请填写该栏目在数据库中的表名(只限英文或英文+数字组合)');
                            }
                            ?>
                        </i></label>

                </td>
            </tr>


            <tr>
                <td width="100" align="right">编辑设置</td>
                <td align="left">
                    <label><input type="checkbox"
                                  name="listnoadd"<?php if (isset($csetting['listnoadd']) && $csetting['listnoadd'] == 1) {
                            echo(' checked');
                        } ?>>禁止添加</label>
                    <label><input type="checkbox"
                                  name="listnoedit"<?php if (isset($csetting['listnoedit']) && $csetting['listnoedit'] == 1) {
                            echo(' checked');
                        } ?>>禁止编辑</label>
                    <label><input type="checkbox"
                                  name="listnodel"<?php if (isset($csetting['listnodel']) && $csetting['listnodel'] == 1) {
                            echo(' checked');
                        } ?>>禁止删除</label>
                    <label><input type="checkbox"
                                  name="listarticlemove"<?php if (isset($csetting['listarticlemove']) && $csetting['listarticlemove'] == 1) {
                            echo(' checked');
                        } ?>>文章转移</label>
                    <label><input type="checkbox"
                                  name="listadminuid"<?php if (isset($csetting['listadminuid']) && $csetting['listadminuid'] == 1) {
                            echo(' checked');
                        } ?>>文章限制</label>
                    <label><input type="checkbox"
                                  name="listcopy"<?php if (isset($csetting['listcopy']) && $csetting['listcopy'] == 1) {
                            echo(' checked');
                        } ?>>显示复制按钮</label>
                    <label><input type="checkbox"
                                  name="listshowadminname"<?php if (isset($csetting['listshowadminname']) && $csetting['listshowadminname'] == 1) {
                            echo(' checked');
                        } ?>>显示文章作者</label>
                    <label><input type="checkbox"
                                  name="listfidshow"<?php if (isset($csetting['listfidshow']) && $csetting['listfidshow'] == 1) {
                            echo(' checked');
                        } ?>>默认显示父分类</label>
                </td>
            </tr>
            <tr>
                <td width="100" align="right">前台设置</td>
                <td align="left">
                    <label><input type="checkbox" class="disable_tips2"
                                  name="ifshow2"<?php if (isset($link['ifshow']) && $link['ifshow'] == 0) {
                            echo(' checked');
                        } ?>>禁用该栏目</label>
                    <label><input type="checkbox" class="disable_tips22"
                                  name="ifshownav2"<?php if (isset($link['ifshownav']) && $link['ifshownav'] == 1) {
                            echo(' checked');
                        } ?>>导航栏显示</label>
                    <label><input type="checkbox"
                                  name="newwindow2"<?php if (isset($link['newwindow']) && $link['newwindow'] == 1) {
                            echo(' checked');
                        } ?>>新窗口中打开</label>
                </td>
            </tr>

            <tr>
                <td width="100" align="right">文章列表显示</td>
                <td align="left">
                    默认显示数量:
                    <input class="inputtext" type="text" size="5" name="temppage_size"
                           value="<?php if (isset($csetting['temppage_size'])) {
                               echo($csetting['temppage_size']);
                           } else {
                               echo('');
                           } ?>">
                    &nbsp;&nbsp;&nbsp;默认排序方式:
                    <input class="inputtext inputshowtips" type="text" size="30" name="temppage_order"
                           value="<?php if (isset($csetting['temppage_order'])) {
                               echo($csetting['temppage_order']);
                           } else {
                               echo('');
                           } ?>"> <i class="ishowtips">如: id desc</i>
                </td>
            </tr>


            <tr>
                <td width="100" align="right">栏目页面</td>
                <td align="left">

                    <label>栏目地址: <input class="inputtext" type="text" size="35" name="channel_url2"
                                        value="<?php if (isset($csetting['channel_url'])) {
                                            echo($csetting['channel_url']);
                                        } ?>"></label>
                    &nbsp;&nbsp;&nbsp;&nbsp;<label>页面缓存时间: <input class="inputtext" type="text" size="5"
                                                                  name="channel_urlcache2"
                                                                  value="<?php if (isset($csetting['channel_urlcache'])) {
                                                                      echo($csetting['channel_urlcache']);
                                                                  } else {
                                                                      echo('0');
                                                                  } ?>"> <i>秒</i></label>
                    <label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" id="template2"
                                                          name="template2"
                                                          value="<?php if (isset($csetting['template'])) {
                                                              echo($csetting['template']);
                                                          } ?>"></label>

                    <br><br>
                    <label>分页地址: <input class="inputtext" type="text" size="35" name="channel_pageurl"
                                        value="<?php if (isset($csetting['channel_pageurl'])) {
                                            echo($csetting['channel_pageurl']);
                                        } ?>"></label>
                    &nbsp;&nbsp;&nbsp;&nbsp;<label>页面缓存时间: <input class="inputtext" type="text" size="5"
                                                                  name="channel_pageurlcache"
                                                                  value="<?php if (isset($csetting['channel_pageurlcache'])) {
                                                                      echo($csetting['channel_pageurlcache']);
                                                                  } else {
                                                                      echo('0');
                                                                  } ?>"> <i>秒</i></label>
                    <label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" id="templatelist"
                                                          name="templatelist"
                                                          value="<?php if (isset($csetting['templatelist'])) {
                                                              echo($csetting['templatelist']);
                                                          } ?>"></label>

                    <br><br>

                    <label>文章地址: <input class="inputtext" type="text" size="35" name="channel_articleurl"
                                        value="<?php if (isset($csetting['channel_articleurl'])) {
                                            echo($csetting['channel_articleurl']);
                                        } else {
                                            echo('');
                                        } ?>"></label>
                    &nbsp;&nbsp;&nbsp;&nbsp;<label>页面缓存时间: <input class="inputtext" type="text" size="5"
                                                                  name="channel_articleurlcache"
                                                                  value="<?php if (isset($csetting['channel_articleurlcache'])) {
                                                                      echo($csetting['channel_articleurlcache']);
                                                                  } else {
                                                                      echo('0');
                                                                  } ?>"> <i>秒</i></label>
                    <label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" id="templatearticle"
                                                          name="templatearticle"
                                                          value="<?php if (isset($csetting['templatearticle'])) {
                                                              echo($csetting['templatearticle']);
                                                          } ?>"></label>


                </td>
            </tr>
        </table>
    </div>
    <!-- 过渡栏目 -->
    <div style="display:none" id="table5">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class=""
               style="border-top:0px;border-bottom:0px;">
            <tr>
                <td width="100" align="right">前台设置</td>
                <td align="left">
                    <label><input type="checkbox" class="disable_tips"
                                  name="ifshow5"<?php if (isset($link['ifshow']) && $link['ifshow'] == 0) {
                            echo(' checked');
                        } ?>>禁用该栏目</label>
                    <label><input type="checkbox"
                                  name="ifshownav5"<?php if (isset($link['ifshownav']) && $link['ifshownav'] == 1) {
                            echo(' checked');
                        } ?>>导航栏显示</label>
                    <label><input type="checkbox"
                                  name="newwindow5"<?php if (isset($link['newwindow']) && $link['newwindow'] == 1) {
                            echo(' checked');
                        } ?>>新窗口中打开</label>

                </td>
            </tr>
        </table>
    </div>

    <!-- 前台链接 -->
    <div style="display:none" id="table3">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class=""
               style="border-top:0px;border-bottom:0px;">
            <tr>
                <td width="100" align="right">前台设置</td>
                <td align="left">
                    链接地址:&nbsp;<input type="text" class="inputtext" name="cvalue" size="50"
                                      value="<?php if (strlen($link['cvalue']) < 50) {
                                          echo($link['cvalue']);
                                      } ?>">
                    <label><input type="checkbox" class="disable_tips"
                                  name="ifshow3"<?php if (isset($link['ifshow']) && $link['ifshow'] == 0) {
                            echo(' checked');
                        } ?>>禁用该栏目</label>
                    <label><input type="checkbox"
                                  name="ifshownav3"<?php if (isset($link['ifshownav']) && $link['ifshownav'] == 1) {
                            echo(' checked');
                        } ?>>导航栏显示</label>
                    <label><input type="checkbox"
                                  name="newwindow3"<?php if (isset($link['newwindow']) && $link['newwindow'] == 1) {
                            echo(' checked');
                        } ?>>新窗口中打开</label>

                </td>
            </tr>
        </table>
    </div>

    <!-- 后台链接 -->
    <div style="display:none" id="table4">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class=""
               style="border-top:0px;border-bottom:0px;">
            <tr>
                <td width="100" align="right">链接地址</td>
                <td align="left">
                    <input type="text" class="inputtext" name="cvalue1" size="50"
                           value="<?php if (strlen($link['cvalue']) < 50) {
                               echo($link['cvalue']);
                           } ?>">
                    <label><input type="checkbox"
                                  name="newwindow4"<?php if (isset($link['newwindow']) && $link['newwindow'] == 1) {
                            echo(' checked');
                        } ?>>新窗口中打开</label>
                    <br>
                    <p>链接地址中可以使用(cid)占位符，获取该后台栏目的cid</p>
                </td>
            </tr>
        </table>
    </div>

    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="" style="border-top:0px;border-bottom:0px;">
        <tr>
            <td width="100" align="right" valign="top">其他页面[<a href="javascript:" class="addotherpage">增加</a>]</td>
            <td align="left" id="otherpage">
                <?php
                $otherpagearray = array();
                if (isset($csetting['otherpage'])) {
                    $otherpagearray = json_decode($csetting['otherpage'], 1);
                }
                foreach ($otherpagearray as $key => $val) {
                    echo('<div>
<label>页面地址: <input class="inputtext" type="text" size="35" name="otherpageurl[]" value="' . $val['uri'] . '"></label>
&nbsp;&nbsp;&nbsp;&nbsp;<label>页面缓存时间: <input class="inputtext" type="text" size="5" name="otherpagecache[]" value="' . $val['cache'] . '"> <i>秒</i></label>
<label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" name="otherpagetemplate[]" value="' . $val['res'] . '"></label>
<a href="javascript:;"  class="delthispage">删除</a><br><br>
</div>');
                }
                ?>
            </td>
        </tr>
        <tr>
            <td width="100" align="right">栏目排序</td>
            <td align="left">
                <input class="inputtext" type="text" name="corder" size="10" value="<?php echo($link['corder']); ?>">
            </td>
        </tr>
    </table>
    </td></tr>
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic"
           style="border-top:0px;border-bottom:0px;">
        <tr>
            <td width="100"></td>
            <td>
                <input class="btn btn140  btn-primary" type="submit" value="提交" style="width:120px;"/>&nbsp;&nbsp;
                <a href="?do=sadmin_cin&cid=<?php echo($cid); ?>&cinkind=1" class="actionBtn">导入栏目配置</a>
            </td>
        </tr>
    </table>
</form>
</div>
</div>


<script type="text/javascript">
    showtable(<?php echo($link['ckind'])?>);

    function showtable(id) {
        document.getElementById('table1').style.display = "none";
        document.getElementById('table2').style.display = "none";
        document.getElementById('table3').style.display = "none";
        document.getElementById('table4').style.display = "none";
        document.getElementById('table5').style.display = "none";
        document.getElementById('table' + id).style.display = "";
    }

    $(function () {
        $('.addotherpage').click(function () {
            $('#otherpage').append($('#newotherpage').html());
        });

        $(document).on('click', '.delthispage', function () {
            $(this).parent().remove();
        });

        $('.disable_tips1').change(function () {
            if ($(this).prop('checked')) {
                alert('禁用该栏目后,导航栏中不会显示该栏目,栏目页面与其他页面将无法访问');
            }
        });
        $('.disable_tips2').change(function () {
            if ($(this).prop('checked')) {
                alert('禁用该栏目后,导航栏中不会显示该栏目,栏目页面与其他页面将无法访问');
            }
        });
        $('.inputshowtips').focus(function () {
            $(this).next().show();
        });
        $('.inputshowtips').blur(function () {
            $(this).next().hide();
        });


    });
</script>

<div id="newotherpage" style="display:none">
    <div>
        <label>页面地址: <input class="inputtext" type="text" size="35" name="otherpageurl[]" value=""></label>
        &nbsp;&nbsp;&nbsp;&nbsp;<label>页面缓存时间: <input class="inputtext" type="text" size="5" name="otherpagecache[]"
                                                      value="0"> <i>秒</i></label>
        <label>&nbsp;&nbsp;&nbsp;控制器文件: <input class="inputtext" type="text" size="30" name="otherpagetemplate[]"
                                              value=""></label>
        <a href="javascript:" class="delthispage">删除</a><br><br>
    </div>
</div>